import type { App } from "vue";
import type { RouteRecordRaw } from "vue-router";

import { createWebHistory, createRouter } from "vue-router";

const currentRoutes: RouteRecordRaw[] = [
  {
    path: "/",
    name: "TmpHome",
    component: () => import("@/modules/home/views/index.vue"),
  },
  {
    path: "/ai",
    name: "AI",
    component: () => import("@/modules/aiPrompt/views/index.vue"),
  },
  {
    path: "/elPages",
    name: "ElPages",
    component: () => import("@/modules/elPages/views/index.vue"),
  },
  {
    path: "/layout",
    name: "Layout",
    component: () => import("@/layouts/index.vue"),
    children: [
      {
        path: "",
        name: "layoutHome",
        component: () => import("@/modules/home/views/index.vue"),
      },
    ],
  },
];

//创建history路由实例
export const router = createRouter({
  history: createWebHistory(),
  routes: currentRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});

// 暴露初始化路由的方法
export function initRouter(app: App<Element>): void {
  app.use(router);
}
